home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 118 / cd-rom 118.iso / aplic / open / openofficeorg2.cab / body.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2005-01-31  |  15.9 KB  |  392 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.  
  4.    $RCSfile: body.xsl,v $
  5.  
  6.    $Revision: 1.4 $
  7.  
  8.    last change: $Author: rt $ $Date: 2005/01/28 15:21:49 $
  9.  
  10.    The Contents of this file are made available subject to the terms of
  11.    either of the following licenses
  12.  
  13.           - GNU Lesser General Public License Version 2.1
  14.           - Sun Industry Standards Source License Version 1.1
  15.  
  16.    Sun Microsystems Inc., October, 2000
  17.  
  18.    GNU Lesser General Public License Version 2.1
  19.    =============================================
  20.    Copyright 2000 by Sun Microsystems, Inc.
  21.    901 San Antonio Road, Palo Alto, CA 94303, USA
  22.  
  23.    This library is free software; you can redistribute it and/or
  24.    modify it under the terms of the GNU Lesser General Public
  25.    License version 2.1, as published by the Free Software Foundation.
  26.  
  27.    This library is distributed in the hope that it will be useful,
  28.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  29.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  30.    Lesser General Public License for more details.
  31.  
  32.    You should have received a copy of the GNU Lesser General Public
  33.    License along with this library; if not, write to the Free Software
  34.    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  35.    MA  02111-1307  USA
  36.  
  37.  
  38.    Sun Industry Standards Source License Version 1.1
  39.    =================================================
  40.    The contents of this file are subject to the Sun Industry Standards
  41.    Source License Version 1.1 (the "License"); You may not use this file
  42.    except in compliance with the License. You may obtain a copy of the
  43.    License at http://www.openoffice.org/license.html.
  44.  
  45.    Software provided under this License is provided on an "AS IS" basis,
  46.    WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
  47.    WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
  48.    MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
  49.    See the License for the specific provisions governing your rights and
  50.    obligations concerning the Software.
  51.  
  52.    The Initial Developer of the Original Code is: Sun Microsystems, Inc.
  53.  
  54.    Copyright ┬⌐ 2002 by Sun Microsystems, Inc.
  55.  
  56.    All Rights Reserved.
  57.  
  58.    Contributor(s): _______________________________________
  59.  
  60. -->
  61. <!--
  62.     For further documentation and updates visit http://xml.openoffice.org/sx2ml
  63. -->
  64. <xsl:stylesheet version="1.0"
  65.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  66.     xmlns:office="http://openoffice.org/2000/office"
  67.     xmlns:style="http://openoffice.org/2000/style"
  68.     xmlns:text="http://openoffice.org/2000/text"
  69.     xmlns:table="http://openoffice.org/2000/table"
  70.     xmlns:draw="http://openoffice.org/2000/drawing"
  71.     xmlns:fo="http://www.w3.org/1999/XSL/Format"
  72.     xmlns:xlink="http://www.w3.org/1999/xlink"
  73.     xmlns:number="http://openoffice.org/2000/datastyle"
  74.     xmlns:svg="http://www.w3.org/2000/svg"
  75.     xmlns:chart="http://openoffice.org/2000/chart"
  76.     xmlns:dr3d="http://openoffice.org/2000/dr3d"
  77.     xmlns:math="http://www.w3.org/1998/Math/MathML"
  78.     xmlns:form="http://openoffice.org/2000/form"
  79.     xmlns:script="http://openoffice.org/2000/script"
  80.     xmlns:dc="http://purl.org/dc/elements/1.1/"
  81.     xmlns:meta="http://openoffice.org/2000/meta"
  82.     xmlns:config="http://openoffice.org/2001/config"
  83.     xmlns:help="http://openoffice.org/2000/help"
  84.     xmlns:java="http://xml.apache.org/xslt/java"
  85.     xmlns:urlencoder="http://www.jclark.com/xt/java/java.net.URLEncoder"
  86.     exclude-result-prefixes="office style text table draw fo xlink number svg chart dr3d math form script dc meta config help java urlencoder">
  87.  
  88.  
  89.     <xsl:include href="table_of_content.xsl" />
  90.  
  91.  
  92.     <!-- ****************** -->
  93.     <!-- *** Whitespace *** -->
  94.     <!-- ****************** -->
  95.  
  96.     <xsl:template match="text:s">
  97.         <xsl:call-template name="write-breakable-whitespace">
  98.             <xsl:with-param name="whitespaces" select="@text:c" />
  99.         </xsl:call-template>
  100.     </xsl:template>
  101.  
  102.  
  103.     <!--write the number of 'whitespaces' -->
  104.     <xsl:template name="write-breakable-whitespace">
  105.         <xsl:param name="whitespaces" />
  106.  
  107.         <!--write two space chars as the normal white space character will be stripped
  108.             and the other is able to break -->
  109.         <xsl:text> </xsl:text>
  110.         <xsl:if test="$whitespaces >= 2">
  111.             <xsl:call-template name="write-breakable-whitespace-2">
  112.                 <xsl:with-param name="whitespaces" select="$whitespaces - 1" />
  113.             </xsl:call-template>
  114.         </xsl:if>
  115.     </xsl:template>
  116.  
  117.  
  118.     <!--write the number of 'whitespaces' -->
  119.     <xsl:template name="write-breakable-whitespace-2">
  120.         <xsl:param name="whitespaces" />
  121.         <!--write two space chars as the normal white space character will be stripped
  122.             and the other is able to break -->
  123.         <xsl:text> </xsl:text>
  124.         <xsl:if test="$whitespaces >= 2">
  125.             <xsl:call-template name="write-breakable-whitespace">
  126.                 <xsl:with-param name="whitespaces" select="$whitespaces - 1" />
  127.             </xsl:call-template>
  128.         </xsl:if>
  129.     </xsl:template>
  130.  
  131.  
  132.  
  133.     <!--
  134.     TABHANDLING PROBLEM: Tabs are possible to be shown in the HTML text file, but will be later stripped as whitespaces.
  135.         To prevent this one way would be the PRE tag which unfortunately ALWAYS result into a line-break. No surrounding NOBR tags help.
  136.  
  137.     <xsl:template match="text:tab-stop">
  138.         <xsl:if test="not(preceding-sibling::text:tab-stop)">
  139.             <xsl:element namespace="{$namespace}" name="pre"><xsl:text> </xsl:text><xsl:for-each select="following-sibling::text:tab-stop"><xsl:text> </xsl:text></xsl:for-each></xsl:element>
  140.         </xsl:if>
  141.      </xsl:template>
  142.  
  143.     <xsl:template match="text:tab-stop"><xsl:text> </xsl:text></xsl:template>
  144.     -->
  145.     <!-- currentSolution: 8 non-breakable-spaces instead of a TAB is an approximation.
  146.          Sometimes less spaces than 8 might be needed and the output might be more difficult to read -->
  147.     <xsl:template match="text:tab-stop">
  148.         <xsl:call-template name="write-breakable-whitespace">
  149.             <xsl:with-param name="whitespaces" select="8" />
  150.         </xsl:call-template>
  151.     </xsl:template>
  152.  
  153.  
  154.  
  155.     <!-- *************** -->
  156.     <!-- *** Textbox *** -->
  157.     <!-- *************** -->
  158.  
  159.     <!-- ID / NAME of text-box -->
  160.     <xsl:template match="@draw:name">
  161.         <xsl:attribute name="id">
  162.             <xsl:value-of select="translate(., '. %()/\+', '_')" />
  163.         </xsl:attribute>
  164.     </xsl:template>
  165.  
  166.  
  167.  
  168.     <xsl:template match="text:line-break">
  169.         <xsl:element namespace="{$namespace}" name="br" />
  170.     </xsl:template>
  171.  
  172.  
  173.  
  174.     <!-- currently there have to be an explicit call of the style attribute nodes, maybe the attributes nodes have no priority only order relevant-->
  175.     <!-- STRANGE: checked with biorythm.sxc a simple xsl:apply-templates did not recognice the styles. Maybe caused by the template match order?  -->
  176.     <xsl:template name="apply-styles-and-content">
  177.         <xsl:param name="globalData" />
  178.  
  179.         <xsl:apply-templates select="@text:style-name | @draw:style-name | @draw:text-style-name | @table:style-name"><!-- | @presentation:style-name -->
  180.             <xsl:with-param name="globalData" select="$globalData" />
  181.         </xsl:apply-templates>
  182.  
  183.         <xsl:apply-templates>
  184.             <xsl:with-param name="globalData" select="$globalData" />
  185.         </xsl:apply-templates>
  186.     </xsl:template>
  187.  
  188.  
  189.  
  190.     <xsl:template match="text:sequence">
  191.         <xsl:param name="globalData" />
  192.  
  193.         <xsl:apply-templates>
  194.             <xsl:with-param name="globalData" select="$globalData" />
  195.         </xsl:apply-templates>
  196.     </xsl:template>
  197.  
  198.  
  199.     <!-- ************************ -->
  200.     <!-- *** Reference Fields *** -->
  201.     <!-- ************************ -->
  202.  
  203.     <xsl:template match="text:reference-ref">
  204.         <xsl:param name="globalData" />
  205.         <!-- Java is needed as we have to encode the relative links (bug#102311) -->
  206.         <xsl:choose>
  207.             <xsl:when test="$javaEnabled">
  208.                 <xsl:element namespace="{$namespace}" name="a">
  209.                     <xsl:attribute name="href">
  210.                         <xsl:text>#</xsl:text>
  211.                         <xsl:call-template name="encode-string">
  212.                         <!-- the space has to be normalized,
  213.                             otherwise an illegal argument exception will be thrown for XT-->
  214.                             <xsl:with-param name="textToBeEncoded" select="@text:ref-name" />
  215.                         </xsl:call-template>
  216.                     </xsl:attribute>
  217.  
  218.                     <xsl:apply-templates>
  219.                         <xsl:with-param name="globalData" select="$globalData" />
  220.                     </xsl:apply-templates>
  221.                 </xsl:element>
  222.             </xsl:when>
  223.             <xsl:otherwise>
  224.                 <xsl:apply-templates>
  225.                     <xsl:with-param name="globalData" select="$globalData" />
  226.                 </xsl:apply-templates>
  227.             </xsl:otherwise>
  228.         </xsl:choose>
  229.     </xsl:template>
  230.  
  231.     <xsl:template match="text:reference-mark">
  232.         <xsl:param name="globalData" />
  233.  
  234.         <!-- Java is needed as we have to encode the relative links (bug#102311) -->
  235.         <xsl:choose>
  236.             <xsl:when test="$javaEnabled">
  237.                 <xsl:element namespace="{$namespace}" name="a">
  238.                     <xsl:attribute name="name">
  239.                         <xsl:call-template name="encode-string">
  240.                         <!-- the space has to be normalized,
  241.                             otherwise an illegal argument exception will be thrown for XT-->
  242.                             <xsl:with-param name="textToBeEncoded" select="@text:name" />
  243.                         </xsl:call-template>
  244.                     </xsl:attribute>
  245.  
  246.                     <xsl:apply-templates>
  247.                         <xsl:with-param name="globalData" select="$globalData" />
  248.                     </xsl:apply-templates>
  249.  
  250.                 </xsl:element>
  251.             </xsl:when>
  252.             <xsl:otherwise>
  253.                 <xsl:apply-templates>
  254.                     <xsl:with-param name="globalData" select="$globalData" />
  255.                 </xsl:apply-templates>
  256.             </xsl:otherwise>
  257.         </xsl:choose>
  258.     </xsl:template>
  259.  
  260.  
  261.  
  262.     <xsl:template match="text:reference-mark-start">
  263.         <xsl:param name="globalData" />
  264.  
  265.         <!-- Java is needed as we have to encode the relative links (bug#102311) -->
  266.         <xsl:choose>
  267.             <xsl:when test="$javaEnabled">
  268.                 <xsl:element namespace="{$namespace}" name="a">
  269.                     <xsl:attribute name="name">
  270.                         <xsl:call-template name="encode-string">
  271.                         <!-- the space has to be normalized,
  272.                             otherwise an illegal argument exception will be thrown for XT-->
  273.                             <xsl:with-param name="textToBeEncoded" select="@text:name" />
  274.                         </xsl:call-template>
  275.                     </xsl:attribute>
  276.  
  277.                     <xsl:variable name="endOfReference">
  278.                         <xsl:for-each select="text:reference-mark-end[@name=current()/@text:name]">
  279.                             <xsl:value-of select="position()" />
  280.                         </xsl:for-each>
  281.                     </xsl:variable>
  282.  
  283.                     <xsl:for-each select="following-sibling::*[position() < $endOfReference]">
  284.                         <xsl:apply-templates>
  285.                             <xsl:with-param name="globalData" select="$globalData" />
  286.                         </xsl:apply-templates>
  287.                     </xsl:for-each>
  288.                 </xsl:element>
  289.             </xsl:when>
  290.             <xsl:otherwise>
  291.                 <xsl:apply-templates>
  292.                     <xsl:with-param name="globalData" select="$globalData" />
  293.                 </xsl:apply-templates>
  294.             </xsl:otherwise>
  295.         </xsl:choose>
  296.     </xsl:template>
  297.  
  298.  
  299.  
  300.  
  301.     <!-- *************** -->
  302.     <!-- *** HELPER  *** -->
  303.     <!-- *************** -->
  304.  
  305.  
  306.     <xsl:template name="create-href">
  307.         <xsl:param name="href" />
  308.  
  309.         <xsl:choose>
  310.             <!-- internal OOo URL used in content tables -->
  311.             <xsl:when test="contains($href, '%7Coutline')">
  312.                 <!-- the simple workaround for content tables in a single document is to create create an anchor from every heading element
  313.                      work-around downside: Multiple identical headings won't refer always to the first.
  314.                 -->
  315.                 <xsl:text>#</xsl:text>
  316.                 <xsl:variable name="title"><xsl:apply-templates mode="concatenate" /></xsl:variable>
  317.                 <xsl:call-template name="encode-string">
  318.                 <!-- the space has to be normalized,
  319.                     otherwise an illegal argument exception will be thrown for XT-->
  320.                     <xsl:with-param name="textToBeEncoded" select="normalize-space(string($title))" />
  321.                 </xsl:call-template>
  322.             </xsl:when>
  323.             <xsl:otherwise>
  324.                 <xsl:choose>
  325.                      <!-- for images jared in open office document -->
  326.                     <xsl:when test="starts-with($href, '#')">
  327.                         <xsl:choose>
  328.                             <xsl:when test="starts-with($href, '#.')">
  329.                                 <!-- creating an absolute http URL to the packed image file (removing the '.')-->
  330.                                 <xsl:value-of select="concat($sourceBaseURL, '/', substring-after($href, '#.'), $optionalURLSuffix)" />
  331.                             </xsl:when>
  332.                             <xsl:otherwise>
  333.                                 <!-- creating an absolute http URL to the packed image file -->
  334.                                 <xsl:value-of select="concat($sourceBaseURL, '/', substring-after($href, '#'), $optionalURLSuffix)" />
  335.                             </xsl:otherwise>
  336.                         </xsl:choose>
  337.                     </xsl:when>
  338.                      <!-- for absolute URLs -->
  339.                     <xsl:when test="contains($href, ':')">
  340.                         <xsl:value-of select="concat($href, $optionalURLSuffix)" />
  341.                     </xsl:when>
  342.                      <!-- for relative URLs -->
  343.                     <xsl:otherwise>
  344.                         <xsl:value-of select="concat($targetBaseURL, $href, $optionalURLSuffix)" />
  345.                     </xsl:otherwise>
  346.                 </xsl:choose>
  347.             </xsl:otherwise>
  348.         </xsl:choose>
  349.  
  350.     </xsl:template>
  351.  
  352.     <xsl:template match="text()" mode="concatenate"><xsl:value-of select="."/></xsl:template>
  353.     <xsl:template match="*" mode="concatenate"><xsl:apply-templates mode="concatenate"/></xsl:template>
  354.  
  355.     <!-- ********************* -->
  356.     <!-- *** Common Helper *** -->
  357.     <!-- ********************* -->
  358.  
  359.     <!-- Chapters from the Content Table have currently no anchor to child documents in OOo XML.
  360.          As solution, whenever a a master document  every header of the HTML output gets get's an anchor in the Therefore-->
  361.     <xsl:template name="encode-string">
  362.         <xsl:param name="encoding" select="'UTF-8'" />
  363.         <xsl:param name="textToBeEncoded" />
  364.  
  365.         <xsl:choose>
  366.             <xsl:when test="function-available('urlencoder:encode')">
  367.                 <xsl:value-of select="translate(urlencoder:encode(normalize-space($textToBeEncoded),$encoding), '%+', '__')" />
  368.             </xsl:when>
  369.             <xsl:when test="function-available('java:java.net.URLEncoder.encode')">
  370.                 <xsl:value-of select="translate(java:java.net.URLEncoder.encode(string(normalize-space($textToBeEncoded)),string($encoding)), '%+', '__')" />
  371.             </xsl:when>
  372.             <xsl:otherwise>
  373.                 <xsl:message terminate="yes">ERROR: Function not found: java:java.net.URLEncoder.encode</xsl:message>
  374.             </xsl:otherwise>
  375.         </xsl:choose>
  376.     </xsl:template>
  377.  
  378.  
  379.     <!-- ******************** -->
  380.     <!-- *** Common Rules *** -->
  381.     <!-- ******************** -->
  382.  
  383.     <!-- deactivating default template -->
  384.     <xsl:template match="*" />
  385.  
  386.     <!-- allowing all matched text nodes -->
  387.     <xsl:template match="text()">
  388.         <xsl:value-of select="." />
  389.     </xsl:template>
  390.  
  391. </xsl:stylesheet>
  392.